package asynch;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;


/*
*   生产者
*
* */
public class Producer {

    public static void main(String[] args) throws Exception{
        //1。创建生产者
        DefaultMQProducer wx = new DefaultMQProducer("wx");

        //2. 设置NameService地址
        wx.setNamesrvAddr("localhost:9876");

        //3.启动
        wx.start();

        //4.创建消息对象，发送
        Message message = new Message("sync", "holle", "这是我的时代".getBytes(StandardCharsets.UTF_8));
        wx.send(message, new SendCallback() {
            public void onSuccess(SendResult sendResult) {
                System.out.println("消费成功");
            }

            public void onException(Throwable throwable) {
                throwable.printStackTrace();
                System.out.println("消费失败");
            }
        });

        //5.关闭
   //     wx.shutdown();

    }
//
}
